package cn.clx.org.controller;

import cn.clx.basic.util.AjaxResult;
import cn.clx.basic.util.PageList;
import cn.clx.org.domain.Dictionarydetail;
import cn.clx.org.mapper.DictionarydetailMapper;
import cn.clx.org.query.DictionarydetailQuery;
import cn.clx.org.service.IDictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionarydetail")
public class DictionarydetailController {

    @Autowired
    private IDictionarydetailService dictionarydetailService;

    @Autowired
    private DictionarydetailMapper dictionarydetailMapper;

    /**
     * 查询全部
     * @return
     */
 /*   @GetMapping
    public List<Dictionarydetail> queryAll(){
        return dictionarydetailService.queryAll();
    }*/

    /**
     * id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public List<Dictionarydetail> queryById(@PathVariable("id") Long id){
        return dictionarydetailMapper.loadType(id);
    }

    /**
     * 新增or修改
     * @param
     * @return
     */
    @PutMapping
    public AjaxResult updOrsave(@RequestBody Dictionarydetail Dictionarydetail){

        try {
            if(Dictionarydetail.getId()==null){
                dictionarydetailService.save(Dictionarydetail);
            }else {
                dictionarydetailService.update(Dictionarydetail);
            }
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setMessage("程序出错，殴打程序员中").setSuccess(false);
        }
    }
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        try {
            dictionarydetailService.removeById(id);
            return AjaxResult.getAjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setMessage("程序出错，殴打程序员中").setSuccess(false);
        }
    }
    @PostMapping
    public PageList<Dictionarydetail> queryPage(@RequestBody DictionarydetailQuery query){
        System.out.println(query);
        return dictionarydetailService.queryPage(query);
    }

}
